const fs = require('fs');
//const result=JSON.parse(fs.readFileSync('pokedesk.json'));
//console.log(result)

const pokedesk = JSON.parse(fs.readFileSync('pokedesk.json'));
//console.log(pokedesk)
const widgetTree = pokedesk.widgetTree;
const children = widgetTree.children;
const options = widgetTree.options;
//console.log(widgetTree)

const children1 = children[0]

//for(var k in children1){
//	console.log(k)
//}

degui(widgetTree) 
//Panel_OtherSite 查找

//递归 {classname：'', name: '', children: '', options: ''} 格式数据

function degui(data) {
	//判断递归停止调节
	if (data.options.name == 'Panel_OtherSite') {
		pokerData(data) 
		return
	}
	//据需扫描数据
	let children = data.children
	let len = children.length
	for (var i = 0; i < len; i++) {
		let data = children[i]
		if (data.children && data.options) {
			degui(data)
		}
	}
}

/**
 * 座位布局
 * */
function pokerData(data) {
	//		fs.writeFileSync('fsf.json', JSON.stringify(data))
//	console.log(data)

	const seatData = data.children;
	const josnData = [] //保存的新数据
	for (var i = 0; i < seatData.length; i++) {
		varseat = seatData[i]
		josnData.push({})
		seatDataFun(varseat, josnData[i])
	}
	console.log(josnData)
	fs.writeFileSync('bkImg1.json', JSON.stringify(josnData))
}

//需要的数据的列表
var ke = ['name', 'tag', 'x', 'y', 'height', 'width'];
//截取有用数据  递归 {classname：'', name: '', children: '', options: ''} 格式数据
function seatDataFun(data, newData) {
	const da = {}
	newData[data.options.name] = {}  //去掉
	//拿取有用数据
	var ke = ['name', 'tag', 'x', 'y'];
//	for (var i = 0; i < ke.length; i++) {
//		
//		newData[data.options.name][ke[i]] = data.options[ke[i]]
//	}

	newData[data.options.name]['left'] = data.options['x']
	newData[data.options.name]['top'] = data.options['y']
	newData[data.options.name]['height'] = data.options['height']
	newData[data.options.name]['width'] = data.options['width']
//	newData[data.options.name] = da
	//据需扫描数据
	let children = data.children
	let len = children.length
	for (var i = 0; i < len; i++) {
		
		if (children[i].children && children[i].options) {
			seatDataFun(children[i], newData[data.options.name])
		}
	}
}